	//注册页面
	var urlType = '',
		dataType = '',
		valUsername = '',
		valPhone = '',
		valVerifCode = '',//图片验证码
		valPhoneVerifCode = '',//手机号验证码
		valPassword = '',//密码
		valConfirmPwd = '',//再次确认密码
		valChecked = '',//接受协议
		agrrement = '';


	var userName = false,
		userPhone = false,
		userCode = false;
		
	var onOff = true;
	
	var onOffVerify = true;
	$('#content input').eq(5).on('click',function(){
		//可以注释
		onOff =! onOff;
		if(onOff){
			console.log(onOff)
		}else{
			console.log(onOff)
		}
	})

var piPwd_reg = '';

//手机号获得焦点事件
	$('#content input').eq(1).on('focus',function(){
		$('#userPhone').css({
			'display':'none',
			'color':''
		})

	})

	$('#content input').eq(1).on('input',function(){
		var strLength = $('#content input').eq(1).val();
		if(strLength.length == 11){
			piPwd_reg = /^1[34578]\d{9}/.test($('#content input').eq(1).val());
				//失去焦点的时候  开始验证
				if(piPwd_reg){
					urlType = "/register/validatePhone";
					dataType = "phone="+ $('#content input').eq(1).val();
					askPostDate2(urlType);
				}else{

					$('#userPhone').text('('+ '手机号的格式错误' +')')
					$('#userPhone').css({
						'display':'block',
						'color':'red'
					})
			}
			return;
		}

	})
	//用户名验证
	$('#content input').eq(0).on('blur',function(){
		//失去焦点的时候  开始验证
		urlType = "/register/validateUsername";
		dataType = "username="+ $('#content input').eq(0).val();
		askPostData1(urlType);
	})

	$('#content input').eq(0).on('focus',function(){
		$('#userName').css({
			'display':'none',
			'color':''
		})
	})

	function onClickBtb(){

		$('#content button').eq(0).on('click',function(){
			urlType = '/phone/sendPhoneVerifCode';
			dataType = "phone="+ $('#content input').eq(1).val();

			
			if(onOffVerify == true){
				askPostData(urlType);
			}
		})
	}

	//短息验证信息的
	//这是post 请求方式
	function askPostData4(num){
		$.ajax({
			url:host + num,
			type:'post',
			data:dataType,
			success:function(res){
				console.log(res)
				if(res.success == true){
					login(valUsername,valPassword);
				}else{
					alert(res.message)
				}
			}
		});
	}

	function login(num1,num2){
		//接口  2.1.29  提交登录信息
		urlType = '/login/submit';
		dataType ="account="+num1+"&"+"password="+num2+"&"+"rememberMe="+true;

		askPostData5(urlType);
	}

	function askPostData5(num){

		$.ajax({
			url:host + num,
			data:dataType,
			type:'post',
			success:function(res){
				console.log(res)

				if(res.success == true){
					console.log("你已注册成功")

					Cookie.setCookie('phone',res.data['phone'])

					Cookie.setCookie('username',res.data['username'])

					Cookie.setCookie('qq',res.data['qq'])

					Cookie.setCookie('address',res.data['address'])

					Cookie.setCookie('wechat',res.data['wechat'])

					Cookie.setCookie('gender',res.data['gender'])

					//存储uuid
					Cookie.setCookie('uuid',res.data['uuid'])
					// 电话及签名
					var hash = hex_md5(strConstant + res.data['uuid']);

					Cookie.setCookie('signature',hash);

					//	跳转到首页  储存cookies 值
					window.location.href = 'index.html';
				}else{
					console.log("您注册失败")
					alert(res['message'])
				}
			}
		});
	}
	$('#content input').eq(1).on('click',function(){
		$('#content button').eq(0).text("发送验证码");
	})

	//短息验证信息的
	 //这是post 请求方式
	function askPostData(num){
		$.ajax({
			url:host + num,
			type:'post',
			data:dataType,
			success:function(res){
				console.log(res)
				if(res.success == true){
					onOffVerify = false;
					//11/18 New created
				           var countdown = 120;
				           $('#content button').eq(0).text('倒计时 ' + countdown + 's');
				            countdown--;
				            var timer = setInterval(function(){
				               $('#content button').eq(0).text('倒计时 ' + countdown + 's');
				                countdown--;
				                if(countdown < 0){
				                	onOffVerify = true;
				                    clearInterval(timer);
				                    $('#content button').eq(0).text('获取验证码');
				                }
				            },1000);
//				        }else{
//				            $btn.text(data.message == "发送验证码出错" ? "发送失败" :data.message);
//				            setTimeout(function(){
//				                $btn.text('获取验证码');
//				            },1500);
//				            $btn.removeClass('disabled');
//				        }

				}else{
//					$('#content button').eq(0).text(res.message);
				}
			}
		});
	}



// $('#content button').eq(1).text('发送验证码')
	//这是用户名请求接口
	function askPostData1(num){
		$.ajax({
			url:host + num,
			type:'post',
			data:dataType,
			success:function(res){
				console.log(res)
				if(res.success == true){
					userName = res.success;

					$('#userName').text('('+ '此用户可用' +')')
					$('#userName').css({
						'display':'block',
						'color':'green'
					})
				}else{
					$('#userName').text('('+ res.message +')')
					$('#userName').css({
						'display':'block',
						'color':'red'
					})
				}
			}
		});
	}


	//电话号码是失去焦点验证
	function askPostDate2(num){
		$.ajax({
			url:host + num,
			type:'post',
			data:dataType,
			success:function(res){
				if(res.success == true){

					$('#userPhone').text('('+ '此手机号可用' +')')
					$('#userPhone').css({
						'display':'block',
						'color':'green'
					})
					onClickBtb();

				}else{
					$('#userPhone').text('('+ res.message +')')
					$('#userPhone').css({
						'display':'block',
						'color':'red'
					})
				}
			}
		})
	}


	//两个true 才可以点击  提交
$('#content button').last().on('click',function(){
	if($('#content input').eq(3).val() === $('#content input').eq(4).val()){

		valUsername = $('#content input').eq(0).val();
		valPhone = $('#content input').eq(1).val();
		valPhoneVerifCode = $('#content input').eq(2).val();
		valPassword = $('#content input').eq(3).val();
		valConfirmPwd = $('#content input').eq(4).val();
		//接口2.1.28   提交页面注册信息
		if(valUsername && valPhone && valPhoneVerifCode && valPassword && valConfirmPwd){
            urlType = '/register/submit';
            //全局变量  获取数据
            dataType = "phone="+ valPhone + "&username=" + valUsername + "&phoneVerifCode=" + valPhoneVerifCode + "&password=" + valPassword + "&confirmPwd=" + valConfirmPwd + "&checked=" + onOff + "&agrrement=" + 'on';
            //最终的总的注册提交  这个时候在完成密码的校验

            askPostData4(urlType);
		}else {
		    alert('参数不能为空')
        }


	}
})

    $(function () {
        $('#goBack').on('click', function () {
            window.history.go(-1)
        })
    })
